define([
        '../../common/service',
        './comment'
    ],
    function(
        http,
        Comment
    ) {
        /**
         * { function_description }
         *
         * @class
         * @param      {<type>}  mid      { 当前ID }
         * @param      {<type>}  prevMid  { 前一个ID }
         * @param      {<type>}  nextMid  { 下一个ID }
         */
        var PicView = function(mid, extParams) {
            var self = this;
            self.mid = mid;
            self.extParams = extParams;
            self.init();
        };
        PicView.prototype = $.extend(PicView.prototype, {
            defaults: {
                lazyload: './imgs/lazyload.gif',
                loadding: './imgs/loading.gif'
            },
            init: function() {
                var DOM;
                this.config = $.extend({}, this.defaults, this.options);
                this.DOM = DOM = this._createDOM();
                this._setCss()._data()._bingEvt()._closeEvt();
                return this;
            },
            cacheInit: function() {
                var DOM;
                this.config = $.extend({}, this.defaults, this.options);
                this.DOM = DOM = this._createDOM();
                this._setCss()._cacheData()._bingEvt()._closeEvt();
            },
            _data: function() {
                var DOM = this.DOM,
                    self = this;
                var params = {
                    mongodId: self.mid
                }
                http.do('/adresource/getAdimagesById', {
                    param: JSON.stringify(params)
                }, 'POST').then(function(result) {
                    if (result.flag == 'fail') {
                        self.hideLoading();
                        kit.alert2(result.msg);
                        return;
                    }
                    self.hideLoading();

                    self.imgobj = result.data;
                    var p = {
                        img: result.data
                    }
                    self._setData(p);

                }, function(msg, data, type, errorCode) {
                    self.hideLoading();
                    kit.alert2('获取列表失败！');
                });
                return self;
            },
            _cacheData: function() {
                var DOM = this.DOM,
                    self = this;
                var p = {
                    img: self.imgobj
                }
                self._setData(p);
                return self;
            },
            _setData: function(obj) {
                var DOM = this.DOM,
                    self = this;
                DOM.img.hide();
                DOM.photo.css("background", "url(" + self.config.loadding + ") no-repeat center center");
                self._loadImage(obj.img.visitPath, function() {
                    DOM.photo.css("background", "none");
                    DOM.img.attr('src', obj.img.visitPath)[self.config.fadeIn === true ? "fadeIn" : 'show']();
                });
                var g = '全部';
                DOM.fileName.find('p').html(obj.img.name);
                DOM.scale.find('span').html(obj.img.resourceType == 'CAROUSEL' ? (I18N.getText('imageManage', 'one2oneImage')) : (I18N.getText('imageManage', 'one2manyImage'))).css('padding-left', '30px');
                DOM.uploadTime.html(I18N.getText('imageManage', 'uploadTime') + moment(new Date(obj.img.createTime)).format('YYYY-MM-DD HH:mm:ss'));
                DOM.language.find('p').html(obj.img.languages ? (obj.img.languages[0] ? obj.img.languages.join(', ') : '') : '');
                DOM.gender.find('p').html((obj.img.gender * 1 == 0) ? I18N.getText('imageManage', 'all') : (obj.img.gender * 1 == 1 ? I18N.getText('imageManage', 'male') : I18N.getText('imageManage', 'famale')));
                DOM.deleteBtn.data('mid', obj.img.id);
                $('#dialoag-btn-review').data('mid', obj.img.id);
                var reviewUrl = window.location.href;
                if (reviewUrl.indexOf('imageReview') > -1) {
                    //第三方图片 支持评价
                    $('#dialoag-btn-comment').removeClass("hidden");
                    if (obj.img.reviewStatus == 5) {
                        $('#dialoag-btn-review').removeClass('hidden');
                        $('#dialoag-btn-review').off('click').on('click', function() {
                            var mid = $(this).data('mid');



                            $('#examine-image-modal').modal('show');
                            $('#examine-image-modal .btn-primary').off('click').on('click', function(e) {

                                var par = [{
                                    mongodbId: mid,
                                    reviewStatus: 1
                                }]
                                self.showLoading();
                                http.do('/adresource/saveImgTags', {
                                    param: JSON.stringify(par)
                                }, 'POST').then(function(result) {
                                    if (result.flag == 'fail') {
                                        self.hideLoading();
                                        kit.alert2(result.msg);
                                        return;
                                    }
                                    self.hideLoading();
                                    kit.alert2('审核成功');
                                    $('#dialoag-btn-review').remove();
                                    //审核通过可以编辑
                                    $('#dialoag-btn-edit').removeClass("hidden");
                                    var reviewAction = $('.review-action[data-mid="' + mid + '"]');
                                    if (reviewAction[0] && result.data.results && result.data.results[0]) {
                                        var nowTr = reviewAction.parents('tr.adimage-data')
                                        reviewAction.html('---').removeClass('review-action');
                                        $('td[revies-status]', nowTr).html(I18N.getText('imageManage', 'byManualReview'));
                                        $('td[revies-reviewer]', nowTr).html(result.data.results[0].reviewer);
                                        $('td[revies-reviewTime]', nowTr).html(moment(new Date(result.data.results[0].reviewTime)).format('YYYY/MM/DD HH:mm:ss'));
                                    }

                                    $('#examine-image-modal').modal('hide');


                                }, function(msg, data, type, errorCode) {
                                    self.hideLoading();
                                    kit.alert2(I18N.getText('imageManage', 'getDatafail'));
                                    $('#examine-image-modal').modal('hide');
                                });

                            });

                        });
                    } else {
                        $('#dialoag-btn-review').remove();
                    }

                    if (obj.img.reviewStatus == 1) {
                        //第三方图片 人工审核通过支持编辑
                        $('#dialoag-btn-edit').removeClass("hidden");
                    }

                } else {
                    $('#dialoag-btn-edit').removeClass('hidden');
                }
                if (self.extParams && self.extParams.isMy == 'true' && window.sessionStorage.roleId != 6) {
                    $('a.ui-dialog-deleteBtn').show();
                } else {
                    $('a.ui-dialog-deleteBtn').hide();
                }
                if (obj.img.appNames[0]) {
                    var params = {
                        typeId: 2
                    };


                    self.showLoading();
                    http.do('/connectionobjects/searchConnectionObjectsByResourceManage', {
                        param: JSON.stringify(params)
                    }, 'POST').then(function(result) {
                        if (result.flag == 'fail') {
                            self.hideLoading();
                            kit.alert2(result.msg);
                            return;
                        }
                        self.hideLoading();
                        var apps = result.data;
                        var results = [];
                        if (apps && apps.length > 0) {
                            apps = _.sortBy(apps, function(item) {
                                return item.name.toLowerCase();
                            });
                            $.each(obj.img.appNames, function(index, v) {
                                var app = self.findApp(v, apps);
                                if (app) {
                                    results.push(app.name);
                                }

                            })
                        }
                        DOM.apps.find('p').text(results[0] ? results.join(', ') : '');
                    }, function(msg, data, type, errorCode) {
                        self.hideLoading();
                        kit.alert2(I18N.getText('imageManage', 'getDatafail'));
                    });

                }

                return self;
            },
            _bingEvt: function() {
                var DOM = this.DOM,
                    self = this;
                DOM.arrowRight.off('click').on('click', function(event) {
                    event.preventDefault();
                    var nextMid = self._hasNext();
                    if (nextMid.length > 0) {
                        self.mid = nextMid;
                        self.init();
                    } else {
                        common.msgs.pop_up(I18N.getText('imageManage', 'lastPage'), 'info');
                    }
                });
                self._hasNext();
                DOM.arrowLeft.off('click').on('click', function(event) {
                    event.preventDefault();
                    var prevMid = self._hasPrev();
                    if (prevMid.length > 0) {
                        self.mid = prevMid;
                        self.init();
                    } else {
                        common.msgs.pop_up(I18N.getText('imageManage', 'firstPage'), 'info');
                    }
                });
                self._hasPrev();

                $('#dialoag-btn-edit').off('click').on('click', function(e) {
                    $('.ui-dialog-wrap .ui-dialog-tags p').toggleClass('hidden');
                    $('#dialoag-btn-edit').toggleClass('hidden');
                    $('#dialoag-btn-submit').toggleClass('hidden');
                    $('#dialoag-btn-cancel').toggleClass('hidden');
                    self._initFileName(self.imgobj);
                    self._initTags(self.imgobj);
                    $('.ui-dialog-arrowLeft').hide();
                    $('.ui-dialog-arrowRight').hide();
                });
                $('#dialoag-btn-cancel').off('click').on('click', function(e) {
                    self.cacheInit();
                });
                $('#dialoag-btn-submit').off('click').on('click', function(e) {
                    self.saveAdImages();
                });

                $('#dialoag-btn-comment').off('click').on('click', function(e) {
                    //$('.ui-dialog.ui-widget').css({
                    //    'z-index': '200001'
                    //});
                    //$('.ui-widget-overlay.ui-front').css({
                    //    'z-index': '200000!important'
                    //});
                    new Comment(self.imgobj.mongodbId);
                });

                return self;
            },
            _resize: function(arrLen) {
                var DOM = this.DOM,
                    self = this;
                $(window).bind('resize', function() {
                    DOM.photo.css('height', (DOM.primary.height() - 75));
                    DOM.lock.css('height', $(document).height());
                });

                return this;
            },
            _loadImage: function(url, callback) {
                var image = new Image(),
                    arr = [];
                image.src = url;
                if (image.complete) {
                    arr.push(image.width);
                    arr.push(image.height);
                    if (typeof callback !== 'undefined') callback.call(this, arr);
                    return;
                }
                image.onload = function() {
                    arr.push(image.width);
                    arr.push(image.height);
                    if (typeof callback !== 'undefined') callback.call(this, arr);
                }
            },
            _lazyload: function() {
                var DOM = this.DOM,
                    elem = this.ulElem.find('img'),
                    ML, start, end;
                if (typeof arguments[0] !== 'undefined') {
                    ML = arguments[0];
                } else {
                    ML = parseInt(this.index / this.thumbNum) * this._getChange();
                }

                start = ML / (this.liWidth + this.config.fix),
                    end = (start + this.thumbNum + 1 > this.len) ? this.len : (start + this.thumbNum + 1);

                for (; start < end; start++) {
                    var src = elem.eq(start).attr('src'),
                        data_src = elem.eq(start).attr('data-src');
                    if (src != data_src) {
                        elem[start].src = data_src;
                    }
                }

                return this;
            },

            //返回需要偏移的值
            _getChange: function() {
                return this.thumbNum * (this.liWidth + this.config.fix);
            },

            //设置偏移值
            _moveX: function(index) {
                var change = this._getChange(),
                    ML = -parseInt(index / this.thumbNum) * change;
                this.ulElem.stop(false, true).animate({
                    'margin-left': ML
                });
            },
            _setCss: function() {
                var DOM = this.DOM,
                    zIndex = 940,
                    hei = $(document).height();
                DOM.wrap.css('z-index', zIndex);
                DOM.lock.css({
                    'position': 'absolute',
                    'top': '0px',
                    'left': '0px',
                    'width': '100%',
                    'height': hei,
                    'opacity': 0.7,
                    'background': '#000',
                    'z-index': --zIndex
                });
                DOM.photo.css('height', (DOM.primary.height() - 75));
                $('.ui-dialog-wrap .ui-dialog-photo a em').css('background-image', 'url(./imgs/arrow.png)');
                return this;
            },
            _createDOM: function() {
                var self = this;
                var tpl = document.createElement('div');
                $('.ui-dialog-wrap').remove();
                $('#ui-dialog-lock').remove();
                tpl.innerHTML = self.templates;
                tpl.className = 'ui-dialog-wrap';
                document.body.appendChild(tpl);
                $('body').append('<div id="ui-dialog-lock"></div>');
                var DOM = {
                        wrap: $(tpl),
                        lock: $('#ui-dialog-lock')
                    },
                    i = 0,
                    elem = tpl.getElementsByTagName('*'),
                    elemLen = elem.length;

                for (; i < elemLen; i++) {
                    var name = elem[i].className.replace('ui-dialog-', '').replace('ui-clearfix', '').trim();
                    if (name) DOM[name] = $(elem[i]);
                }
                if (self.extParams && self.extParams.isMy == 'true' && window.sessionStorage.roleId != 6) {
                    $('a.ui-dialog-deleteBtn').show();
                } else {
                    $('a.ui-dialog-deleteBtn').hide();
                }

                return DOM;
            },
            /**
             * [initAppTag 初始化应用标签]
             * @param  {[type]} data [description]
             * @return {[type]}      [description]
             */
            _closeEvt: function() {
                var self = this;
                var DOM = this.DOM;

                var removeDOM = function() {
                    DOM.wrap.remove();
                    DOM.lock.remove();
                };
                DOM.close.bind('click', removeDOM);
                DOM.lock.bind('click', removeDOM);
                return this;
            },
            /**
             * [_hasNext 是否有下一个节点,如果有则返回下一节点的id]
             * @return {[type]}      [description]
             */
            _hasNext: function() {
                var self = this;
                var nextMid = '';
                //普通图片
                var nextObj = $('div[data-mid="' + self.mid + '"]').parents('tr.adimage-data').nextAll("tr.adimage-data")[0];
                //轮播图片
                var nextCarouselObj = null;
                var carouselObjs = $('div.thumbnail-div[slider-type="carousel"]');
                if (carouselObjs.length > 0) {
                    for (var i = 0; i < carouselObjs.length; i++) {
                        var carouselObj = carouselObjs[i];
                        if ($(carouselObj).data('mid') == self.mid) {
                            if ((i + 1) < carouselObjs.length) {
                                nextCarouselObj = carouselObjs[i + 1];
                                break;
                            }
                        }
                    };
                }

                if (nextObj) {
                    nextMid = $(nextObj).find('div[data-mid]').data('mid');
                } else if (nextCarouselObj) {
                    nextMid = $(nextCarouselObj).data('mid');
                }
                if (nextMid.length > 0) {
                    $('.ui-dialog-arrowRight').removeClass('hidden');
                } else {
                    $('.ui-dialog-arrowRight').addClass('hidden');
                }
                return nextMid;
            },
            /**
             * [_hasPrev 是否有上一个节点,如果有则返回上一节点的id]
             * @return {Boolean} [description]
             */
            _hasPrev: function() {
                var self = this;
                var prevMid = '';
                var prevObj = $('div[data-mid="' + self.mid + '"]').parents('tr.adimage-data').prevAll("tr.adimage-data")[0];

                //轮播图片
                var prevCarouselObj = null;
                var carouselObjs = $('div.thumbnail-div[slider-type="carousel"]');
                if (carouselObjs.length > 0) {
                    for (var i = 0; i < carouselObjs.length; i++) {
                        var carouselObj = carouselObjs[i];
                        if ($(carouselObj).data('mid') == self.mid) {
                            if ((i - 1) > -1) {
                                prevCarouselObj = carouselObjs[i - 1];
                                break;
                            }
                        }
                    };
                }

                if (prevObj) {
                    prevMid = $(prevObj).find('div[data-mid]').data('mid');
                } else if (prevCarouselObj) {
                    prevMid = $(prevCarouselObj).data('mid');
                }
                if (prevMid.length > 0) {
                    $('.ui-dialog-arrowLeft').removeClass('hidden');
                } else {
                    $('.ui-dialog-arrowLeft').addClass('hidden');
                }

                return prevMid;
            },
            showLoading: function($dom) {
                var self = this;
                var loadingArea = $dom ? $dom : $('#widget-grid');
                kit.loading.show(loadingArea);
            },
            hideLoading: function($dom) {
                var self = this;
                var loadingArea = $dom ? $dom : $('#widget-grid');
                kit.loading.hide(loadingArea);
            },
            templates: '' +
                '<div class="ui-dialog-primary">' +
                '<div class="ui-dialog-photo">' +
                '<span></span>' +
                '<img class="ui-dialog-img" />' +
                '<a class="ui-dialog-arrowLeft" href="javascript:void(0);;"><em></em></a>' +
                '<a class="ui-dialog-arrowRight" href="javascript:void(0);;"><em></em></a>' +
                '</div>' +
                '</div>' +
                '<div class="ui-dialog-sidebar">' +
                '<div class="ui-dialog-info ui-clearfix">' +
                '<div class="ui-dialog-details">' +
                '<h3 class="ui-dialog-uploadTime"></h3>' +
                '</div>' +
                '</div>' +
                '<div class="ui-dialog-form">' +
                '<div class="ui-dialog-fileName ui-clearfix"><label>' + I18N.getText('imageManage', 'image') + '</label><div class="ui-dialog-tags"><p></p><input type="text" class="form-group hidden" name="fileName" style="width:80%" /><span class="hidden imgSuffix"></span></div></div>' +
                '<div class="ui-dialog-scale ui-clearfix"><label>' + I18N.getText('imageManage', 'imageRatio') + '</label><span></span></div>' +
                '<div class="ui-dialog-apps ui-clearfix"><label>' + I18N.getText('imageManage', 'app') + '</label><div class="ui-dialog-tags"><p></p><select  multiple="multiple" class="form-group-select2 app-select2 hidden" style="width:100%"  ></select></div></div>' +
                '<div class="ui-dialog-language ui-clearfix"><label>' + I18N.getText('imageManage', 'language') + '</label><div class="ui-dialog-tags"><p></p><select  multiple="multiple" class="form-group-select2 language-select2 hidden" style="width:100%" ></select></div></div>' +
                '<div class="ui-dialog-gender ui-clearfix"><label>' + I18N.getText('imageManage', 'gender') + '</label><div class="ui-dialog-tags"><p></p><select class="form-group-select2 sex-select2 hidden"  style="width:100%"> <option value="">' + I18N.getText('imageManage', 'all') + '</option> <option value="1">' + I18N.getText('imageManage', 'male') + '</option> <option value="2">' + I18N.getText('imageManage', 'famale') + '</option> </select></div></div>' +
                '</div>' +
                '<div class="ui-dialog-footer">' +
                '<button type="button" class="btn btn-default btn-primary hidden" id="dialoag-btn-review">' + I18N.getText('imageManage', 'reviewBtn') + '</button>' +
                '<button type="button" class="btn btn-default btn-primary hidden" id="dialoag-btn-edit">' + I18N.getText('imageManage', 'editBtn') + '</button>' +
                '<button type="button" class="btn btn-default btn-primary hidden" id="dialoag-btn-submit">' + I18N.getText('imageManage', 'saveBtn') + '</button> &nbsp;&nbsp;&nbsp;&nbsp;' +
                '<button type="button" class="btn btn-default hidden" id="dialoag-btn-cancel">' + I18N.getText('imageManage', 'cancelBtn') + '</button>' +
                '<a href="javascript:;" class="ui-dialog-deleteBtn" data-delete data-mid=""><span class="glyphicon glyphicon-trash" aria-hidden="true"></span></a>' +
                '<span id="dialoag-btn-comment" class="comment-action pull-right hidden" style="padding-right:10px"><i class="fa fa-comment-o icon-btn"></i><span>' + I18N.getText('imageManage', 'comment') + '</span></span>' +
                '</div>' +
                '</div>' +
                '<div class="ui-dialog-close">' +
                '<a href="javascript:;">&times;</a>' +
                '</div>',

            _initTags: function(data) {
                var self = this;
                self.initAppTag(data);
                self.initLanguageTag(data);
                self.initSexTag(data);
            },
            _initFileName: function(data) {
                var self = this;
                var fileName = $('input[name=fileName]');
                var img = self.splitImageName(data);
                fileName.toggleClass('hidden');
                $('.imgSuffix').toggleClass('hidden');
                $('.imgSuffix').text(img.imgSuffix);
                fileName.val(img.imgName);
            },
            /**
             * [initAppTag 初始化应用标签]
             * @param  {[type]} data [description]
             * @return {[type]}      [description]
             */
            initAppTag: function(data) {
                var self = this;
                var params = {
                    typeId: 2
                };
                var appSelect = $('select.form-group-select2.app-select2');
                appSelect.empty();
                self.showLoading();
                http.do('/connectionobjects/searchConnectionObjectsByResourceManage', {
                    param: JSON.stringify(params)
                }, 'POST').then(function(result) {
                    if (result.flag == 'fail') {
                        self.hideLoading();
                        kit.alert2(result.msg);
                        return;
                    }
                    self.hideLoading();

                    var app = result.data;
                    var opts = [];
                    if (app && app.length > 0) {
                        app = _.sortBy(app, function(item) {
                            return item.name.toLowerCase();
                        });
                        var options = '';
                        $.each(app, function(index, v) {
                            var selected = false;
                            $.each(data.appNames, function(j, o) {
                                if (v.name == o) {
                                    selected = true;
                                    return false;
                                }
                            });
                            options = options + '<option value="' + v.name + '" ' + (selected ? 'selected="selected"' : '') + '>' + v.name + '</option>';
                        })
                    }
                    appSelect.html(options);
                    appSelect.select2({
                        tags: true
                    });


                }, function(msg, data, type, errorCode) {
                    self.hideLoading();
                    kit.alert2(I18N.getText('imageManage', 'getDatafail'));
                });

            },
            /**
             * [initLanguageTag 初始化语言标签]
             * @param  {[type]} data [description]
             * @return {[type]}      [description]
             */
            initLanguageTag: function(data) {
                var self = this;
                var params = {
                    "type": "adlocale",
                    "locale": I18N.language,
                    "q": ""
                };
                var appSelect = $('select.form-group-select2.language-select2');
                var url = ['search', 'searchAdlocale'];
                var sortName = 'name';
                var idName = 'name';
                var initTagName = 'languages';
                appSelect.empty();
                self.showLoading();
                http.do('/search/searchAdlocale', {
                    param: JSON.stringify(params)
                }, 'POST').then(function(result) {
                    if (result.flag == 'fail') {
                        self.hideLoading();
                        kit.alert2(result.msg);
                        return;
                    }
                    self.hideLoading();
                    var languages = result.data;
                    var opts = [];
                    if (languages && languages.length > 0) {
                        languages = _.sortBy(languages, function(item) {
                            return item.name.toLowerCase();
                        });
                        var options = '';
                        $.each(languages, function(index, v) {
                            var selected = false;
                            if (data.languages) {
                                $.each(data.languages, function(j, o) {
                                    if (v.name == o) {
                                        selected = true;
                                        return false;
                                    }
                                });
                            }
                            options = options + '<option value="' + v.name + '" ' + (selected ? 'selected="selected"' : '') + '>' + v.name + '</option>';
                        })
                    }
                    appSelect.html(options);
                    appSelect.select2({
                        tags: true
                    });
                }, function(msg, data, type, errorCode) {
                    self.hideLoading();
                    kit.alert2(I18N.getText('imageManage', 'getDatafail'));
                });

            },


            _initSearchTag: function(data, $dom, params, url, sortName, idName, idText, initTagName, callback) {
                var self = this;
                var tagSelect = $dom;
                appSelect.empty();

                self.showLoading();
                http.do('/' + url[0] + '/' + url[1] + '', {
                    param: JSON.stringify(params)
                }, 'POST').then(function(result) {
                    if (result.flag == 'fail') {
                        self.hideLoading();
                        kit.alert2(result.msg);
                        return;
                    }
                    self.hideLoading();
                    var opts = [];
                    result.data = _.sortBy(result.data, function(item) {
                        if (item[sortName] && item[sortName].length > 0) {
                            return item[sortName].toLowerCase();
                        } else {
                            0;
                        }
                    });
                    var options = '';
                    $.each(result.data, function(index, v) {
                        var selected = false;
                        if (data[initTagName]) {
                            $.each(data[initTagName], function(x, vv) {
                                datas.push({
                                    id: vv,
                                    text: vv
                                });
                            });
                        }

                        $.each(data.appNames, function(j, o) {
                            if (v.name == o) {
                                selected = true;
                                return false;
                            }
                        });
                        options = options + '<option value="' + v.name + '" ' + (selected ? 'selected="selected"' : '') + '>' + v.name + '</option>';
                    })


                    $.each(result.data, function(index, v) {
                        opts.push({
                            id: v[idName],
                            text: v[idText]
                        })
                    });
                    tagSelect.select2('data', opts);


                    tagSelect.each(function(idx, v) {
                        var imgAppSelct = $(this);
                        var dataMid = self.mid;
                        var datas = [];
                        if (data.mongodbId == dataMid) {
                            if (data[initTagName]) {
                                $.each(data[initTagName], function(x, vv) {
                                    datas.push({
                                        id: vv,
                                        text: vv
                                    });
                                });
                            }
                        }
                        imgAppSelct.select2('data', datas)
                    });



                }, function(msg, data, type, errorCode) {
                    self.hideLoading();
                    kit.alert2(I18N.getText('imageManage', 'getDatafail'));
                });






                if (callback) {
                    callback(tagSelect);
                }
            },


            initSexTag: function(data) {
                var self = this;
                var appSelect = $('select.form-group-select2.sex-select2');
                appSelect.toggleClass('hidden');
                appSelect.each(function(idx, v) {
                    var imgAppSelct = $(this);
                    var dataMid = self.mid;
                    imgAppSelct.find("option[value='" + data.gender + "']").attr("selected", true);
                    imgAppSelct.select2({
                        minimumResultsForSearch: Infinity
                    });
                });

            },
            /**
             * 遍历 apps 找到appName值
             * @param appName
             * @param apps
             */
            findApp: function(appName, apps) {
                var obj;
                $.each(apps, function(idx, v) {
                    if (v.name == appName) {
                        obj = v;
                    }
                });
                return obj;
            },
            saveAdImages: function(e) {
                var self = this;
                var appNames = $('select.app-select2');
                var fileName = $('input[name=fileName]');
                if (appNames.val() == null || appNames.val().length == 0) {
                    appNames.next().testRemind(I18N.getText('imageManage', 'plsSelectApp'));
                    return false;
                }
                if (fileName.val().length == 0) {
                    fileName.testRemind(I18N.getText('imageManage', 'filenameempty'));
                    return false;
                }
                var adimageArr = [];
                $('.ui-dialog-sidebar').each(function(idx, el) {
                    var adimage = {};
                    var appNames = $(this).find('select.app-select2').val();
                    adimage.mongodbId = self.mid;
                    adimage.fileName = fileName.val() + $('.imgSuffix').text();
                    adimage.appNames = appNames;
                    var languages = $(this).find('select.language-select2').val();
                    if (languages) {
                        adimage.languages = languages;
                    } else {
                        adimage.languages = ['']
                    }
                    adimage.gender = $(this).find('select.sex-select2').val();
                    if (adimage.gender == null || adimage.gender.length == 0) {
                        adimage.gender = '0';
                    }
                    adimageArr.push(adimage);
                });

                self.showLoading();
                http.do('/adresource/saveImgTags', {
                    param: JSON.stringify(adimageArr)
                }, 'POST').then(function(result) {
                    if (result.flag == 'fail') {
                        self.hideLoading();
                        kit.alert2(result.msg);
                        return;
                    }
                    self.hideLoading();
                    kit.alert2(I18N.getText('imageManage', 'saveSuccess'));
                    self.init();
                }, function(msg, data, type, errorCode) {
                    self.hideLoading();
                    kit.alert2(I18N.getText('imageManage', 'getDatafail'));
                });

            },
            /**
             * [splitImageName 分割图片名称]
             * @param  {[type]} img [description]
             * @return {[type]}           [description]
             */
            splitImageName: function(img) {
                if (img.name && img.name.length > 0 && (img.name.lastIndexOf('.') > -1)) {
                    var idx = img.name.lastIndexOf('.')
                    img.imgSuffix = img.name.substr(idx);
                    img.imgName = img.name.substr(0, idx);
                } else {
                    img.imgName = img.name;
                    img.imgSuffix = '';
                }
                return img;
            }
        });

        return PicView;
    });
